<?php 
include './c/config.php';

$dbhost='121.41.203.38'; //web1
$mysqliSet = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqliSet->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqliSet->query("SELECT id FROM `uinfo` WHERE `f2` IS NULL ORDER BY `id` DESC LIMIT 0,1");
if($query->num_rows>0){
    
}else{
    exit;
}

$getD=$query->fetch_assoc();
$id=$getD['id'];
$UserFen=0;


 

//单选------
$danxuan=json_decode(file_get_contents('./template/mi/dx.txt'), true);
$tiData=array();
foreach ($danxuan as $k=>$v){
    $tiData[($k+1)]=$v['a'];
}


$dbhost = '121.41.197.22';
echo $dbhost;
echo "<br />";
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT * from `danxuan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
  //  var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $tmpTiVal=strtolower(trim($tiData[$k]));
            if(trim($v) == $tmpTiVal){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}
if ($fen > 0){
    $UserFen=$fen;
}
$mysqli->close();

$dbhost='121.41.203.38'; //web1
echo $dbhost;
echo "<br />";
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT * from `danxuan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    //var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $tmpTiVal=strtolower(trim($tiData[$k]));
            if(trim($v) == $tmpTiVal){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}

if ($fen > $UserFen){
    $UserFen=$fen;
}

$mysqli->close();

echo "<br />";
echo ".......<br />";
$dbhost='47.118.85.222'; //web2
echo $dbhost;
echo "<br />";

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT * from `danxuan` where uid='".$id."'  limit 0,1 ");
if($query->num_rows>0){
    $getUTk=$query->fetch_assoc();
    $yhtj=json_decode($getUTk['yhtj'], true);
    //var_dump($yhtj);
    echo "<br><br>";
    $fen=0;
    foreach ($yhtj as $key => $value){
        foreach ($value as $k => $v ){
            echo $k, '.....', $v, '.....';//$tiData[$k];
            $tmpTiVal=strtolower(trim($tiData[$k]));
            if(trim($v) == $tmpTiVal){
                $fen++;
                echo '.....对了';
            }
            echo "<br />";
        }
    }
    echo "<br />";
    echo $fen,'分';
}
$mysqli->close();
if ($fen > $UserFen){
    $UserFen=$fen;
}

echo "<br /><br />";
echo $id,' :填空题分:';
echo $UserFen;
$mysqliSet->query(" update  `uinfo` set f2='".$UserFen."'  WHERE id='".$id."' ");

$mysqliSet->close();

echo '
<script>
window.setTimeout(function(){
window.location.reload();
}, 10);
</script>
    
';

exit;
